package org.itboys.mobile.controller.web.report;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.service.KitchenReportService;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：农厨_报表_controller_web
 *
 */
@Controller
@RequestMapping("/kitchen/web/report")
public class KitchenReportController extends BaseController {

    @Autowired
    private KitchenReportService reportService;

    /**
     * 质押物  主页
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/sale/index" )
    public  String sale_index(HttpServletRequest request,
                           Model model){
       /* //按天
        if(returnPage==1){
            return "/sunday/product/index";
        //按月
        }else if(returnPage==2){
            return "/sunday/product/score/index";
        }*/
        return "/kitchen/report/sale/index";
    }

    /**
     * 查询销售/采购/积分报表数据
     * @param request
     * @param response
     */
    @RequestMapping("/sale")
    public void sale(HttpServletRequest request,
                        HttpServletResponse response
    ) {
        try {
           Map<String,Object> result=reportService.sale(request);
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgResultDO(result,CommonConstants.SUCCESS));
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }

    /**
     * 采购核销
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/account/index" )
    public  String account_index(HttpServletRequest request,
                                 Model model){
        return "/kitchen/report/account/index";
    }
    @RequestMapping("/account")
    public void account(HttpServletRequest request,
                     HttpServletResponse response
    ) {
        try {
            PageResult<Map<String,Object>> result=reportService.account(request);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }
}
